package com.superjson.showpro.controller;

import com.superjson.showpro.controller.core.BaseContoller;
import com.superjson.showpro.entity.User;
import com.superjson.showpro.service.ArticleCatalogUserService;
import com.superjson.showpro.shared.result.Result;
import com.superjson.showpro.shared.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created By zby on 19:59 2019/5/22
 * 用户查看那篇文章的记录
 */
@RestController("articleCatalogUserController")
@RequestMapping("/article/catalog/user")
public class ArticleCatalogUserController extends BaseContoller {

    @Autowired
    private ArticleCatalogUserService articleCatalogUserService;

    /**
     * Created By zby on 11:32 2019/6/21
     * 添加用户查看哪篇文章的记录
     */
    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public Result saveObj(Long articleId, HttpServletRequest request) {
        User user = getUser(request).getResultData();
        articleCatalogUserService.saveObj(articleId, user, request);
        return ResultUtil.buildSuccess();
    }

    /**
     * Created By zby on 14:29 2019/6/22
     * 获取某篇文章的点击量或某个人文章的点击量
     */
    @RequestMapping(value = "/countClick", method = RequestMethod.GET)
    public Result countClick(Long articleId, Long userId) {
        Long clicks = articleCatalogUserService.countClick(articleId, userId).getResultData();
        return ResultUtil.buildSuccess(clicks);
    }
}
